package com.zhima.controller.admin;

import com.zhima.dto.ZhimaOjPageResult;
import com.zhima.dto.ZhimaOjResult;
import com.zhima.service.OjQuestionAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import static com.zhima.dto.ZhimaOjResult.success;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author zhima
 * @since 2023-08-25
 */
@RestController
@RequestMapping("/audit/admin")
public class OjQuestionAuditAdminController {
    @Autowired
    private OjQuestionAuditService ojQuestionAuditService;


    /**
     * 管理员审核题目
     *
     * @param questionId
     * @param advice
     * @return
     */
    @PostMapping("/{questionId}/{advice}")
    public ZhimaOjResult auditQuestion(@PathVariable("questionId") Long questionId, @PathVariable(value = "advice", required = false) String advice) {
        return success(ojQuestionAuditService.auditQuestion(questionId, advice));
    }

    /**
     * 管理员审核题目
     *
     * @param questionId
     * @return
     */
    @PostMapping("/{questionId}")
    public ZhimaOjResult auditQuestion(@PathVariable("questionId") Long questionId) {
        return success(ojQuestionAuditService.auditQuestion(questionId, null));
    }

    /**
     * 分页查询用户提交的审核记录
     *
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/{pageNum}/{pageSize}")
    public ZhimaOjPageResult pageQueryQuestionNeedAudit(@PathVariable("pageNum") Long pageNum, @PathVariable("pageSize") Long pageSize) {
        return ZhimaOjPageResult.success(ojQuestionAuditService.pageQueryQuestionAudit(null, pageNum, pageSize, true));
    }
}
